//TODO: License Header.

/*
This code is licensed under the BSD license.

*/
package analysis.metrics

import primitives.cluster.ClusterHead
import primitives.graph.Node
import search.util.TreeLoader2
import static Math.min
import primitives.cluster.*;
import primitives.graph.*;
import search.fitnessfunctions.BunchTurboMQFitnessFunction

class EdgeToStateRatioMetric extends Metric{



	public void proc(String[] args) throws IOException{
		String filename = args[0];

		ClusterHead tree = TreeLoader2.loadTreeFromDot(new File(filename));
		
		if(tree == null){
			System.err.println("ERROR: Tree loaded from " + args[0] + " is null. Aborting metric dump.");
			System.exit(-0xBAD);
		}
		try{
			evaluate(tree);
		}catch(NullPointerException npe){
			System.err.println("Caught a NPE! for file " + args[0]);

			ClusterUtils.prettyPrintTree(tree);
			System.exit(-0xBEEF);
		}
		
	}

	public static void main(String[] args){
		new EdgeToStateRatioMetric().proc(args);
	}

	
	double evaluate(ClusterHead tree){
		

		
		int e = tree.nodes.collect{
		    it.transitionsAsT.size()
        }.sum(0)
        
	
        double n = tree.nodes.size()

		print "$e,$n," + (e / n)
        return -1;
	}
	

	
}